import com.example.fenye.mapper.PageMapper;
import com.example.fenye.model.User;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class PageMapperText {
    private SqlSession sqlSession;
    @Before
    public void before() throws IOException {
        System.out.println("before");
        //配置文件地址
        String resource = "mybatis-config.xml";
        //读取配置文件，生成输入流
        InputStream inputStream = Resources.getResourceAsStream(resource);
        //创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //获取sqlSession
        sqlSession = sqlSessionFactory.openSession();
    }
    @Test
    public void PageTest2(){
        PageHelper.startPage(2,3);
        List<User> list = sqlSession.getMapper(PageMapper.class).list();
    }
    @After
    public void after(){
        System.out.println("after");
        //提交
        sqlSession.commit();
        //关闭
        sqlSession.close();
    }
}
